import { produce } from "immer";
import { useEffect, useState } from "react";

interface Obj {
    a: {
        b: number
    }
}

export default function TestImmutable2 () {
    const [state, setState] = useState<Obj>({
        a: {
            b: 1
        }
    })

    useEffect(() => {
        setTimeout(() => {
            setState(produce(state, draft => {
                draft.a.b = 2
            }))
        }, 2000);
    })

    let count = state.a.b
    return <div>{count}</div>
}